var objShell = new ActiveXObject("WScript.Shell");

function jsAlert(msg)
{
    return objShell.Popup(msg, 10000, "CyberArticle", 0);
}


var objCAAutomation = new ActiveXObject("CyberArticle.CAAutomationApp");

function loadMacroString(stringName)
{
    var macroAppGUID = "{6177EACF-51BF-4756-9040-C1511392526C}";
    //
    return objCAAutomation.LoadMacroString(macroAppGUID, stringName);
}

function formatString0(msg)
{
    return loadMacroString(msg);
}

function SaveAsTemplate()
{
    var strMyBooksPath = objShell.RegRead("HKEY_CURRENT_USER\\Software\\WizBrother\\CyberArticle\\MyBooksFolder");
    if (strMyBooksPath == null || strMyBooksPath == "")
    {
        jsAlert(formatString0("PromptSystemError"));
        return;
    }

    if (strMyBooksPath[strMyBooksPath.length - 1] != '\\')
        strMyBooksPath = strMyBooksPath + "\\";
    strMyBooksPath = strMyBooksPath + "NewArticleTemplate\\";
    //
    var node = objCAAutomation.CurrentArticle;
    if (node == null)
    {
        jsAlert(formatString0("PromptViewArticle"));
        return;
    }
    //
    node.Article.SaveAsHTML(strMyBooksPath + node.title + ".htm");
    //
    jsAlert(formatString0("SucceededToSaveTemplate"));
    
}

SaveAsTemplate();

